﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace WpfELearningAuthoringTool
{
    public class MediaUtil
    {
        public static string buildFlashScript(string filePath,string width, string height)
        {
            string fileName = Path.GetFileName(filePath);
            string srcFile = "media/" + fileName;
            string flashScript = " <object width=\"" + width + "\" height=\"" + height + "\" " +
                                "classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" + "\" " +
                              "codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0 " + "\"> " +
                              "<param name=\"SRC\" value=\"" + fileName + "\"> " +
                              "<embed src=\"" + srcFile + "\" width=\"" + width + "\" height=\"" + height + "\"> " +
                              "</embed> " +
                              "</object>";
            return flashScript;
        }
        public static string buildMediaScript(string filePath, string width, string height)
        {
            string fileName = Path.GetFileName(filePath);
            string srcFile = "media/" + fileName;
            string extension = Path.GetExtension(filePath);
            string mediaScript = "";
            if (filePath.Contains(".mp4") || filePath.Contains(".MP4"))
            {
                mediaScript = "<OBJECT CLASSID=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"+"\" "+ 
                              "CODEBASE=\"http://www.apple.com/qtactivex/qtplugin.cab\" width=\""+width +"\" height=\""+height+"\"> "+ 
                              "<PARAM NAME=\"src\" VALUE=\""+fileName+"\" > "+
                              "<PARAM NAME=\"autoplay\" VALUE=\"true"+"\" > "+
                              "<EMBED SRC=\"" + srcFile + "\" TYPE=\"image/x-macpaint" + "\" " + 
                              "PLUGINSPAGE=\"http://www.apple.com/quicktime/download\" WIDTH=\""+width +"\" HEIGHT=\""+height+"\" AUTOPLAY=\"true"+"\"></EMBED> "+
                              "</OBJECT>";
            }
            else if (filePath.Contains(".wmv") || filePath.Contains(".WMV"))
            {
                mediaScript = "<object width=\"" + width + "\" height=\"" + height + "\" " +
                              "type=\"video/x-ms-asf\" url=\"" + srcFile + "\" data=\"" + fileName + "\" " +
                              "classid=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" + "\">" +
                              " <param name=\"url\" value=\"" + srcFile + "\"> " +
                              " <param name=\"filename\" value=\"" + fileName + "\"> " +
                              " <param name=\"autostart\" value=\"1" + "\">" +
                              " <param name=\"uiMode\" value=\"full" + "\">" +
                              " <param name=\"autosize\" value=\"1" + "\">" +
                              " <param name=\"playcount\" value=\"1" + "\">" +
                              " <embed type=\"application/x-mplayer2\" src=\"" + fileName + "\" width=\"" + width + "\" height=\"" + height + "\" " + "autostart=\"true\" showcontrols=\"true\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/" + "\"></embed> " +
                              "</object>";
            }
            return mediaScript;
        }

        public static string buildAudioScript(string filePath, string width, string height)
        {
            string fileName = Path.GetFileName(filePath);
            string srcFile = "media/" + fileName;
            string extension = Path.GetExtension(filePath);
            string mediaScript = "";
            if (filePath.Contains(".wav") || filePath.Contains(".WAV"))
            {
                mediaScript = "<embed type=\"audio/x-wav\" src=\"" + srcFile + "\" autoplay=\"true\" autostart=\"true\" width=\"" + width + "\" height=\"" + height + "\"> ";
            }
            else if (filePath.Contains(".mp3") || filePath.Contains(".MP3"))
            { 
                mediaScript = "<object width=\""+width+"\" height=\""+height+"\"> "+
                               "<param name=\"src\" value=\"" +fileName+"\"> "+
                               "<param name=\"autoplay\" value=\"false" + "\">" +
                               "<param name=\"controller\" value=\"true" + "\">" +
                               "<param name=\"bgcolor\" value=\"#FFFFFF" + "\">" +
                               "<embed src=\"" +srcFile +"\" autostart=\"false\" loop=\"false\" width=\""+width +"\" height=\""+height+"\""+
                               "controller=\"true\" bgcolor=\"#FFFFFF\"></embed> "+
                               "</object>";
            }
            return mediaScript;
        }
       
    }
}
